<?php namespace App\Http\Controllers;

use App\Http\Models\Match;
use App\Http\Models\User;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Session;

class MatchController extends Controller{


    public function index()
    {
        //Session::flush();
        $title='地丰赛事';

        $entries=Match::getList(Input::all());

        return view('match/list',compact('title','entries'));
    }

    public function getDetail($entry)
    {
        $title='赛事详情';
        $input['MTCustomerID']=Session::get(User::$session_key);
        $input['MTMatchID']=$entry->MID;
        $join=Match::getJoinList($input);

        return view('match/detail',compact('title','entry','join'));
    }

    public function doJoin()
    {
        if(!User::Check())
        {
            return Redirect::to('member/index')->withInfo('请先注册！');
        }

        $res=Match::doJoin(Input::all());
        $id=Input::get('MTMatchID','');
        if($res)
        {
            return Redirect::to('match/'.$id.'/detail')->withSuccess('操作成功');
        }else{
            return Redirect::back();
        }
    }
    public function getMyMatch()
    {
        if(!User::Check())
        {
            return Redirect::to('member/index')->withInfo('请先注册！');
        }

        $title='我的赛事';

        $input=Input::all();

        $input['my']=1;

        $entries=Match::getList($input);

        return view('match/list',compact('title','entries'));

    }

}

